/* 
 * 定义itfreer.arcgis.search查询模块
 */
(function(window, angular, undefined){
	/* 
	 * 定义ArcGIS查询模块
	 */
	var itfreerArcgisSearchModule = angular.module('itfreer.arcgis.search', ['itfreer.arcgis.draw', 'itfreer.arcgis.geometryservice']);

	/* 
	 * 定义ArcGIS查询模块
	 */
	itfreerArcgisSearchModule.factory('$itfreer_arcgis_search', 
		function($rootScope, $itfreer_form_core, $itfreer_arcgis_core, 
			$gisObject, $formObject,$http,
			$itfreer_arcgis_draw, $itfreer_arcgis_geometryservice) {
			$itfreer_arcgis_search = {

				/* 
				 * 定义ArcGIS查询模块
				 */
				getDefaultPointSyml : function(){ 
					// 点样式
					var pointSymbol = new esri.symbol.SimpleMarkerSymbol(
						esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10,
						new esri.symbol.SimpleLineSymbol(
								esri.symbol.SimpleLineSymbol.STYLE_SOLID,
								new dojo.Color([
									255,10,10]), 1),
						new dojo.Color([250, 114, 114,
								$gisObject.styleConfig.highLightDefaultStyle.fillOpacity]));
					return pointSymbol;
				},

				/* 
				 * 定义默认选中样式
				 */
				getDefaultFillSyml : function(){ 
					// 线样式
					var outlineSyml = new esri.symbol.SimpleLineSymbol(
						esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([
							250, 11, 11,
							$gisObject.styleConfig.highLightDefaultStyle.fillOpacity]),
						$gisObject.styleConfig.highLightDefaultStyle.strokeWidth);

					// 面默认和选中样式
					var defaultFillSyml = new esri.symbol.SimpleFillSymbol(
						esri.symbol.SimpleFillSymbol.STYLE_SOLID, outlineSyml,
						new dojo.Color([250, 114, 114,
							$gisObject.styleConfig.highLightDefaultStyle.fillOpacity]));
					return defaultFillSyml;
				},

				/* 
				 * 定义ArcGIS查询模块
				 */
				getSelectPointSyml : function(){ 
					// 点样式
					var pointSymbol = new esri.symbol.SimpleMarkerSymbol(
						esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 15,
						new esri.symbol.SimpleLineSymbol(
								esri.symbol.SimpleLineSymbol.STYLE_SOLID,
								new dojo.Color([
									$gisObject.styleConfig.highLightSelectStyle.strokeColor.r,
									$gisObject.styleConfig.highLightSelectStyle.strokeColor.g,
									$gisObject.styleConfig.highLightSelectStyle.strokeColor.b]), 1),
						new dojo.Color([$gisObject.styleConfig.highLightSelectStyle.fillColor.r,
								$gisObject.styleConfig.highLightSelectStyle.fillColor.g,
								$gisObject.styleConfig.highLightSelectStyle.fillColor.b,
								$gisObject.styleConfig.highLightSelectStyle.fillOpacity]));
					return pointSymbol;
				},

				/* 
				 * 定义ArcGIS查询模块
				 */
				getSelectFillSyml : function(){ 
					// 点样式
					var pointSymbol = new esri.symbol.SimpleMarkerSymbol(
						esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,
						new esri.symbol.SimpleLineSymbol(
								esri.symbol.SimpleLineSymbol.STYLE_SOLID,
								new dojo.Color([
									$gisObject.styleConfig.highLightSelectStyle.strokeColor.r,
									$gisObject.styleConfig.highLightSelectStyle.strokeColor.g,
									$gisObject.styleConfig.highLightSelectStyle.strokeColor.b]), 1),
						new dojo.Color([$gisObject.styleConfig.highLightSelectStyle.fillColor.r,
								$gisObject.styleConfig.highLightSelectStyle.fillColor.g,
								$gisObject.styleConfig.highLightSelectStyle.fillColor.b,
								$gisObject.styleConfig.highLightSelectStyle.fillOpacity]));

					// 线样式
					var outlineSyml = new esri.symbol.SimpleLineSymbol(
						esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([
							$gisObject.styleConfig.highLightSelectStyle.strokeColor.r,
							$gisObject.styleConfig.highLightSelectStyle.strokeColor.g,
							$gisObject.styleConfig.highLightSelectStyle.strokeColor.b,
							$gisObject.styleConfig.highLightSelectStyle.fillOpacity]),
						$gisObject.styleConfig.highLightSelectStyle.strokeWidth);
			
					var selectFillSyml = new esri.symbol.SimpleFillSymbol(
						esri.symbol.SimpleFillSymbol.STYLE_SOLID, outlineSyml,
						new dojo.Color([$gisObject.styleConfig.highLightSelectStyle.fillColor.r,
							$gisObject.styleConfig.highLightSelectStyle.fillColor.g,
							$gisObject.styleConfig.highLightSelectStyle.fillColor.b,
							$gisObject.styleConfig.highLightSelectStyle.fillOpacity]));
					return selectFillSyml;
				},

				/**
				 * 初始化查询
				 */
				initSearch : function(searchName, setValue){
					$gisObject.searchParameter[searchName] = {
						// 查询的服务
						url : null,
						// 查询的字段
						selectFields : null,
						// 是否显示小汽泡
						showPop : true,
						// identify查询和find查询的ShowPop参数集
						showPops : {},
						// 是否高亮显示要素
						showFeature : true,
						// identify查询和find查询的ShowFeature参数集
						showFeatures : {},
						// 查询展示样式的标题
						infoTemplateTitle : '',
						// identify查询和find查询的infoTemplateTitle参数集
						infoTemplateTitles : {},
						// 查询展示样式的内容
						infoTemplateContent : '',
						// identify查询和find查询的infoTemplateContent参数集
						infoTemplateContents : {},
						// 查询展示窗口的宽
						infoWindowWidth : 240,
						// identify查询和find查询的infoWindowWidth参数集
						infoWindowWidths : {},
						// 查询展示窗口的高
						infoWindowHeiht : 120,
						// identify查询和find查询的infoWindowHeiht参数集
						infoWindowHeihts : {},
						// 空间查询类型 polygon, line, point
						type : null,
						// 空间查询缓存，单位米
						buffer : null,
						// 属性查询是否在当前的视图范围内
						extent : null,
						// 属性查询的属性参数
						attribute : {},
						// findtask的查询值
						searchText : '',
						// identify查询和find查询的图层IDs
						searchLayerIds : null,
						// 已经查询到的图层ids
						resultLayerIds : [],
						// 查询的分页大小
						searchPageSize : 5,
						// 查询展示样式
						infoTemplate : null,
						// 查询的分页大小
						searchPageIndex : 1,
						// 查询的总页数
						searchPageCount : 0,
						// 查询的总记录数
						searchRowCount : 0,
						// 查询结果列表
						searchResultList : null,
						// 查询的当前页列表
						searchPageList : null,
						// 是否显示查询面板
						searchPanel : true,
						// 是否对查询值做抽稀处理
						simple : false,
						// 是否对查询值做抽稀处理
						simples : [],
						//是否新建图层
						isNewLayer:false,
						//新建的图层
						graphicsLayer:null
					};
					if(setValue){
						$gisObject.searchParameter[searchName] = 
							jQuery.extend(true, $gisObject.searchParameter[searchName], setValue);
					}
					$itfreer_arcgis_draw.deDrawAndClearGraphics();
				},

				/**
				 * 初始化查询，如果存在数据之前的查询数据，则保留数据
				 */
				initSearchKO : function(searchName, setValue){
					if($gisObject.searchParameter[searchName]
						&& $gisObject.searchParameter[searchName].searchPageList
						&& $gisObject.searchParameter[searchName].searchPageList.length>0
						&& $gisObject.searchParameter[searchName].searchPanel==false){
						$itfreer_arcgis_search.showPageResults(searchName);
					}else{
				       	if($gisObject.searchParameter[searchName]
				       		&& $gisObject.searchParameter[searchName].resultLayerIds
				       		&& $gisObject.searchParameter[searchName].resultLayerIds.length>0){
				       		var firstLayerSearchName = $gisObject.searchParameter[searchName].resultLayerIds[0];
				       		$itfreer_arcgis_search.showPageResults(firstLayerSearchName);
				       	}else{
				       		$itfreer_arcgis_search.initSearch(searchName, setValue);
				       	}
					}
					if(setValue.onClick){
						$gisObject.searchParameter.onClick = setValue.onClick;
					}
					else{
						$gisObject.searchParameter.onClick = null;
					}
					if(setValue.getSymbol){
						$gisObject.searchParameter.getSymbol = setValue.getSymbol;
					}
					else{
						$gisObject.searchParameter.getSymbol = null;
					}
				},

			    /**
				 * 属性查询 不通过ArcGIS服务，直接调用自己写的后台
				 */
			    attributeSearchBy : function(searchName,queryObj){
			    	$itfreer_arcgis_draw.onDrawEndEventFunction = null;
					$itfreer_arcgis_geometryservice.onProjectCompleteEventFunction = null;
					$itfreer_arcgis_geometryservice.onSimplifyCompleteEventFunction = null;
					$itfreer_arcgis_geometryservice.onLengthsCompleteEventFunction = null;
					$itfreer_arcgis_geometryservice.onAreasAndLengthsCompleteEventFunction = null;
					$itfreer_arcgis_geometryservice.onBufferCompleteEventFunction = null;
					$itfreer_arcgis_draw.deDrawAndClearGraphics();

					var url = $gisObject.searchParameter[searchName].url;

		          	//信息模板
		          	$gisObject.searchParameter[searchName].infoTemplate = new esri.InfoTemplate();
		          	//设置Title
		          	var title = $gisObject.searchParameter[searchName].infoTemplateTitle;
		          	if(angular.isString(title))
		          		title = title.replace(/~/gm,'$');
		          	$gisObject.searchParameter[searchName].infoTemplate.setTitle(title);

		          	//设置Content
		          	var content = $gisObject.searchParameter[searchName].infoTemplateContent;
		          	if(angular.isString(content)){
		          		if(content.indexOf('<')==-1){
		          			var element = $('#'+content);
				          	if(element && element.length>0){
				          		content = element[0].innerHTML;
				          	}
		          		}
			          	content = content.replace(/~/gm,'$');
		          	}
		          	$gisObject.searchParameter[searchName].infoTemplate.setContent(content);
		          	
		          	
		          	//设置infoWindow的尺寸
		          	$gisObject.map.infoWindow.resize(
		          		$gisObject.searchParameter[searchName].infoWindowWidth, 
		          		$gisObject.searchParameter[searchName].infoWindowHeiht);

		          	
		          	//进行查询
		          	$http({
						method:"POST",
						url:getBasePath()+url,
						data:queryObj||{}
					}).success(function(wktRecords){
						//清除上一次的高亮显示
				       	$itfreer_arcgis_draw.deDrawAndClearGraphics();
				       	
				       	var results = {};
						var features = [];
						results.features = features;
						
						var spatialReference = $gisObject.map.spatialReference;
						var geometry;
						var row;
						var wkt ;
						var feature;
						if(wktRecords.data){
							for(var i=0;i<wktRecords.data.length;i++){
								 row = wktRecords.data[i];
								 wkt = row.WKT;
								 geometry = WKTUtil.read(wkt,spatialReference);
								 feature = new Object();
								 if(row.PHOTO)
									 row.PHOTO1 = row.PHOTO.substr(getBasePath().length);
								 feature.attributes = row;
								 feature.geometry = geometry;
								 features.push(feature);
							}
						}
				       	
			       		$gisObject.searchParameter[searchName].searchPanel = false;
			       		// 初始化查询结果
			       		$gisObject.searchResultList = results.features;
			       		$itfreer_arcgis_search.showSearchResultLRQ(results.features);
			       		//$itfreer_arcgis_search.initSearchResult(searchName, results.features);
					});
			    },
			    
			    /**
			     * lrq
			     */
			    showSearchResultLRQ : function(features){
			    	// 清除结果
			    	$itfreer_arcgis_draw.deDrawAndClearGraphics();

			    	//遍历查询结果
			       	//var pageList = $gisObject.searchParameter[searchName].searchPageList;
			    	var pageList = features;
			    	
			    	try{
				       	
				       	for (var i=0;i<pageList.length; i++){

				       		// 设置要素选中
				          	var feature = pageList[i];
				        	var symbol = $itfreer_arcgis_search.getDefaultPointSyml();
				        	
				        	if($gisObject.searchParameter.getSymbol){
				        		symbol = $gisObject.searchParameter.getSymbol(feature);
				        	}
					       
					       	feature.geometry.spatialReference = $gisObject.map.spatialReference;
							if(!feature.attributes){
								feature.attributes = {};
							}
							var showFeatureAttributesCopy = jQuery.extend(true, {}, feature.attributes);
							var showPopAttributesCopy = jQuery.extend(true, {}, feature.attributes);

							var graphic = new esri.Graphic(feature.geometry, symbol);
					
							graphic.defaultSymbol = symbol;
			          		graphic.attributes = showFeatureAttributesCopy;
							graphic.setInfoTemplate(null);
			          		
							if($gisObject.map.graphics){
			          			$gisObject.map.graphics.add(graphic);
			          		}
				       	}

				       	// 启用map.graphics的鼠标事件
				       	if($gisObject.map.graphics){
				       		$gisObject.map.graphics.enableMouseEvents();
				       	}
					    
					    dojo.disconnect( $gisObject.searchParameter.mouseOverHandle);
					    dojo.disconnect($gisObject.searchParameter.mouseOutHandle);
					    $gisObject.searchParameter.mouseOverHandle = 
					    	dojo.connect($gisObject.map.graphics, "onMouseOver", function (evt){
					    	var graphic = evt.graphic;
					    	if(!graphic.attributes){
					    		return;
					    	}
					    	$gisObject.map.setMapCursor("pointer");
							var pMark = new esri.symbol.PictureMarkerSymbol(getJsBasePath()+"/wdp/images/highlight.png", 25, 25);
							graphic.setSymbol(pMark);

					    });
					    $gisObject.searchParameter.mouseOutHandle = 
					    	dojo.connect($gisObject.map.graphics, "onMouseOut", function (evt){
					       	var graphic = evt.graphic;
					    	if(!graphic.attributes){
					    		return;
					    	}
					    	
					    	if($gisObject.currentSelectedFeature==graphic) return;
					    	
					    	$gisObject.map.setMapCursor("default");
					    	graphic.setSymbol(graphic.defaultSymbol);
					    });
				       	dojo.disconnect($gisObject.graphicsClickHandle);
				       	$gisObject.graphicsClickHandle = dojo.connect($gisObject.map.graphics, "onClick", function (evt){
				       		
				    		var graphic = evt.graphic;
				    		if(!graphic.attributes){
					    		return;
					    	}
				    		if(graphic.attributes.$guid) return;
				    		
				    		if($gisObject.searchParameter.onClick){
				    			$gisObject.searchParameter.onClick(graphic);
				    		}
				    	});
			    	}catch(e){
			    		console.log(e);
			    	}

			    	return pageList;
			    },
			    
			    /**
				 * 初始化查询的分页信息
				 */
			    initSearchResult : function (searchName, rows, noPageResults) {
			    	var rowCount = rows.length;
					if(rowCount<0){
						rowCount = 0;
					}
					var pageSize = $gisObject.searchParameter[searchName].searchPageSize;
					var pCount = rowCount / pageSize;
					pCount = parseInt(pCount);
					if((pageSize*pCount) < rowCount){
						pCount++;
					}
					// 查询的总页数
					$gisObject.searchParameter[searchName].searchPageCount = pCount;
					$gisObject.searchParameter[searchName].searchRowCount = rowCount;
					$gisObject.searchParameter[searchName].searchResultList = rows;
					
					//add by lrs,把结果在地图上显示出来
					$itfreer_arcgis_search.showPageResults(searchName);
					
					//把结果在列表中显示出来
					$itfreer_arcgis_search.setPageIndex(searchName, 1, noPageResults);
				},
				
				/**
				 * 显示分页查询结果
				 */
			    showPageResults : function(searchName){
			    	//这一句，在地图上显示查询结果
					var pageList = $itfreer_arcgis_search.innerShowPageResults(searchName);
			    	if($gisObject.searchParameter[searchName].simple == true && pageList.length>1000){
			    		// 地图是否缩放
				    	dojo.connect($gisObject.map, "onExtentChange", function (extent,delta, levelChange, lod){
				    		if(levelChange 
				    			&& $gisObject.searchParameter[searchName].simple){
				    			$itfreer_arcgis_search.innerShowPageResults(searchName);
				    		}
					    });
			    	}
			    	//设置地图视图范围
			       	var rExtent = $itfreer_arcgis_core.getMaxExtent(pageList);
			       	//$gisObject.map.setExtent(rExtent);
			    },
			    
			    innerShowPageResults : function(searchName){
			    	// 清除结果
			    	$itfreer_arcgis_draw.deDrawAndClearGraphics();

			    	//遍历查询结果
			       	//var pageList = $gisObject.searchParameter[searchName].searchPageList;
			    	var pageList = $gisObject.searchParameter[searchName].searchResultList;
			    	
			    	try{
			    		if($gisObject.searchParameter[searchName].simple == true && pageList.length>1000){
				       		pageList = $itfreer_arcgis_search.simple(pageList);
				       	}
				       	
				       	var infoTemplate = $gisObject.searchParameter[searchName].infoTemplate;
				    	var getSymbolFunction = $gisObject.searchParameter[searchName].getSymbol;
				       	
				       	for (var i=0;i<pageList.length; i++){

				       		// 设置要素选中
				          	var feature = pageList[i];
				          	feature.attributes.searchName = searchName;
				        	var symbol;
					       
					       	if(getSymbolFunction != null){
					       		symbol = getSymbolFunction(feature);
					       	}
					       	if(symbol == null ){
					       		symbol = $itfreer_arcgis_search.getDefaultFillSyml();
						       	if(pageList.length>0 && pageList[0].geometry.type == "point"){
						       		symbol = $itfreer_arcgis_search.getDefaultPointSyml();
						       	}
					       	}

					       	feature.geometry.spatialReference = $gisObject.map.spatialReference;
				          	var showFeature = $gisObject.searchParameter[searchName].showFeature;
				          	var showPop = $gisObject.searchParameter[searchName].showPop;
				          	var showWindows = $gisObject.searchParameter[searchName].showWindows;
							if(!feature.attributes){
								feature.attributes = {};
							}
							var showFeatureAttributesCopy = jQuery.extend(true, {}, feature.attributes);
							var showPopAttributesCopy = jQuery.extend(true, {}, feature.attributes);

				          	if(showFeature){
				          		showFeatureAttributesCopy.$searchName = searchName;
				          		showFeatureAttributesCopy.$isFeature = true;
								showFeatureAttributesCopy.$showFeature = showFeature;
								showFeatureAttributesCopy.$showPop = showPop;
								
								var graphic = new esri.Graphic(feature.geometry, symbol);
						
								graphic.defaultSymbol = symbol;
				          		graphic.attributes = showFeatureAttributesCopy;
				          		if(showWindows == false){
									graphic.setInfoTemplate(null);
								}
								else{
									graphic.setInfoTemplate(infoTemplate);
				          		}
				          		if($gisObject.map.graphics){
				          			$gisObject.map.graphics.add(graphic);
				          		}
				          	}
							
				          	if(showPop){
								showPopAttributesCopy.$searchName = searchName;
								showPopAttributesCopy.$ispop = true;
								showPopAttributesCopy.$popindxe = i;
								showPopAttributesCopy.$showFeature = showFeature;
								showPopAttributesCopy.$showPop = showPop;

							
								// 设置小气泡
								var iconName = "arrow";

								var iconURL = getJsBasePath()+"/arcgis/images/features/" + iconName + ".png";
								var pMark = new esri.symbol.PictureMarkerSymbol(iconURL, 25, 35);
								var _center = $itfreer_arcgis_core.getCenter(feature.geometry);
								var graphic = new esri.Graphic(_center, pMark);
								graphic.attributes = showPopAttributesCopy;
								
								if(showWindows == false){
									graphic.setInfoTemplate(null);
								}
								else{
									graphic.setInfoTemplate(infoTemplate);
				          		}
								if($gisObject.map.graphics){
				          			$gisObject.map.graphics.add(graphic);
				          		}
				          	}
				       	}

				       	// 启用map.graphics的鼠标事件
				       	if($gisObject.map.graphics){
				       		$gisObject.map.graphics.enableMouseEvents();
				       	}
					    
					    dojo.disconnect( $gisObject.searchParameter[searchName].mouseOverHandle);
					    dojo.disconnect($gisObject.searchParameter[searchName].mouseOutHandle);
					    $gisObject.searchParameter[searchName].mouseOverHandle = 
					    	dojo.connect($gisObject.map.graphics, "onMouseOver", function (evt){
					    	var graphic = evt.graphic;
					    	if(!graphic.attributes){
					    		return;
					    	}
					    	$gisObject.map.setMapCursor("pointer");
					    	if(graphic.attributes.$ispop && graphic.attributes.$ispop==true){
					    		$itfreer_arcgis_search.selectPopByGraphic(graphic,searchName);
					    	}

					    	if(graphic.attributes.$isFeature && graphic.attributes.$isFeature==true){
					    		$itfreer_arcgis_search.selectFeatureByGraphic(graphic,searchName);
					    	}
					    });
					    $gisObject.searchParameter[searchName].mouseOutHandle = 
					    	dojo.connect($gisObject.map.graphics, "onMouseOut", function (evt){
					       	var graphic = evt.graphic;
					    	if(!graphic.attributes){
					    		return;
					    	}
					    	
					    	if($gisObject.currentSelectedFeature==graphic) return;
					    	
					    	$gisObject.map.setMapCursor("default");
					    	if(graphic.attributes.$ispop && graphic.attributes.$ispop==true){
					    		$itfreer_arcgis_search.unSelectPopByGraphic(graphic,searchName);
					    	}
					    	
					    	if(graphic.attributes.$isFeature && graphic.attributes.$isFeature==true){
					    		$itfreer_arcgis_search.unSelectFeatureByGraphic(graphic,searchName);
					    	}
					    });
				       	dojo.disconnect($gisObject.graphicsClickHandle);
				       	$gisObject.graphicsClickHandle = dojo.connect($gisObject.map.graphics, "onClick", function (evt){
				       		
				       		alert("click me");
				    		var graphic = evt.graphic;
				    		if(!graphic.attributes){
					    		return;
					    	}
				    		if(graphic.attributes.$guid) return;
				    		
				    		if($gisObject.searchParameter[searchName].onClick){
				    			$gisObject.searchParameter[searchName].onClick(graphic);
				    		}
				    		
				    	});
			    	}catch(e){
			    		console.log(e);
			    	}

			    	return pageList;
			    },

				/**
				 * 周边搜索
				 */
				circle:null,
				neighborLayer:null,
				neighborSearch : function(searchname,searchObj,onClick,onComplete){
					if($itfreer_arcgis_search.neighborLayer==null) {
						$itfreer_arcgis_search.neighborLayer = new esri.layers.GraphicsLayer({id:"neighbor_layer"});
						$gisObject.map.addLayer($itfreer_arcgis_search.neighborLayer);
					}
					$itfreer_arcgis_search.neighborLayer.clear();
					var symbol = new esri.symbol.SimpleFillSymbol();
					var fillColor = esri.Color.fromHex("#4673cc").toRgb();
					fillColor.push(0.5);
					symbol.setColor(fillColor);
					
					var strokeColor = esri.Color.fromHex("#a3b1cc").toRgb();
					strokeColor.push(0.9);
					symbol.outline.setWidth(1).setColor(strokeColor);
					
					var pt = new esri.geometry.Point(Number(searchObj.geometry.x),Number(searchObj.geometry.y));
					pt.spatialReference = map.spatialReference;
					$itfreer_arcgis_search.circle = new esri.geometry.Circle({
			            center: pt,
			            radius: searchObj.radius,
			            radiusUnit: "esriKilometers"
			        });
					
					var graphic = new esri.Graphic($itfreer_arcgis_search.circle, symbol);
					$itfreer_arcgis_search.neighborLayer.add(graphic);
					
					
					// 实例化QueryTask
		          	var queryTask = new esri.tasks.QueryTask(searchObj.url);
		          	// 查询参数
		          	var query = new esri.tasks.Query();
					// 需要返回的字段 ["*"]
		          	query.outFields = ["*"];
		          	//需要返回Geometry
		          	query.returnGeometry = true;
		          	// 处理空间查询
		          	query.geometry = $itfreer_arcgis_search.circle;
					query.outSpatialReference = $gisObject.map.spatialReference;
					query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
					//关键字参数
					query.where = searchObj.where;

					//进行查询
		          	queryTask.execute(query, function (results){
				       	//清除上一次的高亮显示
//				       	$itfreer_arcgis_draw.deDrawAndClearGraphics();
				       	if(!results || results.features.length<=0){
				       		results = {};
				       		results.features = [];
				       	}
				       	$itfreer_arcgis_search.showResultOnLayer(searchname,$itfreer_arcgis_search.neighborLayer, results.features, onClick);
				       	
				       	if(onComplete){
				       		onComplete(results.features);
				       	}
				    });
				},
				
				showResultOnLayer:function(searchname,layer, features, onClick){
			       	if(features.length>1000){
			       		features = $itfreer_arcgis_search.simple(features);
			       	}
			       	
			       	for (var i=0;i<features.length; i++){
			          	var feature = features[i];
			        	var symbol;
				       	feature.geometry.spatialReference = $gisObject.map.spatialReference;
						if(!feature.attributes){
							feature.attributes = {};
						}
						var showFeatureAttributesCopy = jQuery.extend(true, {}, feature.attributes);
						showFeatureAttributesCopy.$searchName = searchname;
						// 设置小气泡
						var iconName = "arrow";
						var iconURL = getJsBasePath()+"/arcgis/images/features/" + iconName + ".png";
						var pMark = new esri.symbol.PictureMarkerSymbol(iconURL, 25, 35);
						var _center = $itfreer_arcgis_core.getCenter(feature.geometry);
						var graphic = new esri.Graphic(_center, pMark);
						graphic.attributes = showFeatureAttributesCopy;
						if(layer){
							layer.add(graphic);
		          		}
		          	}

			       	// 启用map.graphics的鼠标事件
			       	layer.enableMouseEvents();
			       	if($itfreer_arcgis_search.neighborLayerClickHandler){
			       		dojo.disconnect($itfreer_arcgis_search.neighborLayerClickHandler);
			       	}
			       	$itfreer_arcgis_search.neighborLayerClickHandler = dojo.connect(layer, "onClick", function (evt){
			    		var graphic = evt.graphic;
			    		if(!graphic.attributes){
				    		return;
				    	}
			    		if(graphic.attributes.$guid) return;
			    		
			    		if(onClick){
			    			onClick(graphic);
			    		}
			    	});

			    	return features;
			    },
			    
			    setMapFullExtent:function(){
			    	if($gisObject.map && $gisObject.fullExtent){
			    		$gisObject.map.setExtent($gisObject.fullExtent);
			    	}
			    },
			    
			    /**
			     * 获取要素的范围
			     */
			    getExentByFeatures:function(url,where,onSuccess){
			    	// 实例化QueryTask
		          	var queryTask = new esri.tasks.QueryTask(url);
		          	// 查询参数
		          	var query = new esri.tasks.Query();
					// 需要返回的字段 ["*"]
		          	query.outFields = ["*"];
		          	//需要返回Geometry
		          	query.returnGeometry = true;
		          	// 处理空间查询
					//关键字参数
					query.where = where;

					//进行查询
		          	queryTask.execute(query, function (results){
				       	if(!results || results.features.length<=0){
				       		return;
				       	}
				    	var extent = $itfreer_arcgis_core.getMaxExtent(results.features);
//				       	var extent = results.features[0].geometry.getExtent();
//				       	for (var i=0;i<results.features.length;i++)
//				       	{
//				       		extent = extent.union(results.features[i].geometry.getExtent());
//				       	}
				       	if(onSuccess && extent){
				       		onSuccess(extent);
				       	}
				    });
			    },
			    
				/* 
				 * 处理buffer的情况
				 */
				optionBuffer : function(geometry, searchName, identify){
					var buffer = $gisObject.searchParameter[searchName].buffer;
					var mapisdlwkid = $gisObject.mapisdlwkid;

					if(buffer && buffer!="" && buffer!="0"){
						// 先做buffer
						var distances = parseInt(buffer);
						if(distances>0){
							// 如果为地理坐标，则先转换平面，再做缓存
							if(mapisdlwkid){
								$itfreer_arcgis_geometryservice.project([geometry], $gisObject.tywkid);
							}else{
								$itfreer_arcgis_geometryservice.buffer(distances, [geometry]);
							}
						}else{
							// 内部查询
							if(identify){
								$itfreer_arcgis_search.innerIdentifySearch(searchName, geometry);
							}else{
								$itfreer_arcgis_search.innerSpaceSearch(searchName, geometry);
							}
						}
					}else{
						// 内部查询
						if(identify){
							$itfreer_arcgis_search.innerIdentifySearch(searchName, geometry);
						}else{
							$itfreer_arcgis_search.innerSpaceSearch(searchName, geometry);
						}
					}
				},

				/* 
				 * 对象simplify完成后调用方法
				 */
				onSimplifyComplete : function(graphics, searchName){
					$itfreer_arcgis_search.optionBuffer(graphics[0], searchName);
				},

				/* 
				 * 对象投影转换后
				 */
				onProjectComplete  : function(graphics, searchName, identify){
					var mapisdlwkid = $gisObject.mapisdlwkid;
					if(!mapisdlwkid){
						return;
					}

					// 如果是投影坐标，则做Buffer
					if(graphics[0].spatialReference.wkid == $gisObject.tywkid){
						var buffer = $gisObject.searchParameter[searchName].buffer;
						var distances = parseInt(buffer);
						$itfreer_arcgis_geometryservice.buffer(distances, graphics);
					} else if(graphics[0].spatialReference.wkid == $gisObject.dlwkid){
						// 临时显示缓冲区
						var symbol = $itfreer_arcgis_search.getSelectFillSyml();
				       	if(graphics[0].geometry.type == "point"){
				       		symbol = $itfreer_arcgis_search.getSelectPointSyml();
				       	}

						var graphic = new esri.Graphic(graphics[0], symbol);
						if($gisObject.map.graphics){
							$gisObject.map.graphics.add(graphic);
						}

			          	// 等待1.5秒
			          	setTimeout(function(){
							// 如果是地理从标，则查询
							if(identify){
								$itfreer_arcgis_search.innerIdentifySearch(searchName, graphics[0]);
							}else{
								$itfreer_arcgis_search.innerSpaceSearch(searchName, graphics[0]);
							}
			          	},900); 
					}
				},

				/* 
				 * 对象缓冲分析完成
				 */
				onBufferComplete : function (geometries, searchName, identify) {
					var mapisdlwkid = $gisObject.mapisdlwkid;

					if(mapisdlwkid){
						// 如果是地理坐标，需要将投影转换为地理
						$itfreer_arcgis_geometryservice.project(geometries, $gisObject.dlwkid);
					}else{
						// 临时显示缓冲区
						var symbol = $itfreer_arcgis_search.getSelectFillSyml();
				       	if(geometries[0].geometry.type == "point"){
				       		symbol = $itfreer_arcgis_search.getSelectPointSyml();
				       	}
						var graphic = new esri.Graphic(geometries[0], symbol);
						if($gisObject.map.graphics){
							$gisObject.map.graphics.add(graphic);
						}

			          	// 等待1.5秒
			          	setTimeout(function(){
							// 如果是地理从标，则查询
							if(identify){
								$itfreer_arcgis_search.innerIdentifySearch(searchName, geometries[0]);
							}else{
								$itfreer_arcgis_search.innerSpaceSearch(searchName, geometries[0]);
							}
			          	},900); 
					}
				},

 				/**
				 * 获取属性查询条件
				 */
			    getWhereString : function(searchName){
			    	var attribute = $gisObject.searchParameter[searchName].attribute;
			    	if(!attribute){
			    		return "";
			    	}

					var whereString = "";
		    		for(key in attribute){ 
						var fields = key.split(":");
						var field = null;
						var option = null;
						if (fields.length == 2) {
							field = fields[0];
							option = fields[1];
						} else {
							field = key;
							option = "=";
						}
						var value = attribute[key];

						if(value!=""){
							if (option=="=") {
								if (value==("\"null\"")) {
									whereString += field + " is null and ";
								} else {
									if(typeof value == "string"){
										whereString += field + " = '"+value+"' and ";
									}
									else{
										whereString += field + " = "+value+" and ";
									}
								}
							} else if (option==">") {
								whereString += field + " > "+value+" and ";
							} else if (option=="!=") {
								whereString += field + " != '"+value+"' and ";
							} else if (option==">=") {
								whereString += field + " >= "+value+" and ";
							} else if (option=="<") {
								whereString += field + " < "+value+" and ";
							} else if (option=="<=") {
								whereString += field + " <= "+value+" and ";
							} else if (option=="in") {
								whereString += field + " in (" + value.toString() + ") and ";
							} else if (option=="nin") {
								whereString += field + " not in (" + value.toString() + ") and ";
							} else if (option=="isnull") {
								whereString += field + " is null and ";
							} else if (option=="isnnull") {
								whereString += field + " is not null and ";
							} else if (option=="like") {
								whereString += field + " like '" + value.toString() + "' and ";
							} else if (option=="%like") { 
								whereString += field + " like '%" + value.toString() + "' and ";
							} else if (option=="like%") { 
								whereString += field + " like '" + value.toString() + "%' and ";
							}
						}
					}
					if(whereString!=""){
						whereString = whereString.substring(0, whereString.length-4);
					}
					return whereString;
			    },

			    setConfig : function(layerSearchName, searchName){
			    	$gisObject.searchParameter[layerSearchName] = {};
       				$gisObject.searchParameter[layerSearchName].searchPageSize = $gisObject.searchParameter[searchName].searchPageSize;
       				var identifyShowFeature = $gisObject.searchParameter[searchName].showFeatures;
       				if(identifyShowFeature 
       					&& identifyShowFeature.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].showFeature = identifyShowFeature[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].showFeature = $gisObject.searchParameter[searchName].showFeature;
       				}

       				var identifyShowPop = $gisObject.searchParameter[searchName].showPops;
       				if(identifyShowPop 
       					&& identifyShowPop.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].showPop = identifyShowPop[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].showPop = $gisObject.searchParameter[searchName].showPop;
       				}

       				var defaultTitle = $gisObject.searchParameter[searchName].infoTemplateTitle;
       				var infoTemplateTitles = $gisObject.searchParameter[searchName].infoTemplateTitles;
       				if(infoTemplateTitles 
       					&& infoTemplateTitles.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].infoTemplateTitle = infoTemplateTitles[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].infoTemplateTitle = defaultTitle;
       				}

       				var infoTemplateContents = $gisObject.searchParameter[searchName].infoTemplateContents;
       				if(infoTemplateContents 
       					&& infoTemplateContents.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].infoTemplateContent = infoTemplateContents[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].infoTemplateContent = "";
       				}

					var infoWindowWidths = $gisObject.searchParameter[searchName].infoWindowWidths;
       				if(infoWindowWidths 
       					&& infoWindowWidths.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].infoWindowWidth = infoWindowWidths[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].infoWindowWidth = $gisObject.searchParameter[searchName].infoWindowWidth;
       				}

       				var infoWindowHeihts = $gisObject.searchParameter[searchName].infoWindowHeihts;
       				if(infoWindowHeihts 
       					&& infoWindowHeihts.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].infoWindowHeiht = infoWindowHeihts[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].infoWindowHeiht = $gisObject.searchParameter[searchName].infoWindowHeiht;
       				}

       				//信息模板
		          	$gisObject.searchParameter[layerSearchName].infoTemplate = new esri.InfoTemplate();
		          	//设置Title
		          	var title = $gisObject.searchParameter[layerSearchName].infoTemplateTitle;
		          	if(!title){
		          		title = '';
		          	}
		          	title = title.replace(/~/gm,'$');
		          	$gisObject.searchParameter[layerSearchName].infoTemplate.setTitle(title);

		          	//设置Content
		          	var contentId = $gisObject.searchParameter[layerSearchName].infoTemplateContent;
		          	var content = '';
		          	if(contentId && contentId!=''){
		          		var element = $('#'+contentId);
			          	if(element && element.length>0){
			          		content = element[0].innerHTML;
			          	}
		          	}
		          	if(content == null || content == ""){
		          		content = '<b>OBJECTID: </b>~{OBJECTID}';
		          	}
		          	content = content.replace(/~/gm,'$');
		          	$gisObject.searchParameter[layerSearchName].infoTemplate.setContent(content);
		          	//设置infoWindow的尺寸
		          	$gisObject.map.infoWindow.resize(
		          		$gisObject.searchParameter[layerSearchName].infoWindowWidth, 
		          		$gisObject.searchParameter[layerSearchName].infoWindowHeiht);

		          	var simples = $gisObject.searchParameter[searchName].simples;
       				if(simples && simples.hasOwnProperty(layerSearchName)){
       					$gisObject.searchParameter[layerSearchName].simple = simples[layerSearchName];
       				}else{
       					$gisObject.searchParameter[layerSearchName].simple = $gisObject.searchParameter[searchName].simple;
       				}
			    },

			    /**
				 * identify中是否包含指定的图层
				 */
			    hasLayer : function(searchName, layerName){
			    	var layerSearchName = searchName + "_" + layerName;
			    	if($gisObject.searchParameter[searchName].resultLayerIds){
			    		var index = $gisObject.searchParameter[searchName].resultLayerIds.indexOf(layerSearchName);
			    		if(index>=0){
			    			return true;
			    		}else{
			    			return false;
			    		}
			    	}else{
			    		return false;
			    	}
			    },

				isContant : function(featureList, targetfeature, buf){
					var targetCenterPoint = $itfreer_arcgis_core.getCenter(targetfeature.geometry);
					for(var j=0;j<featureList.length;j++){
						var currentCenterPoint = $itfreer_arcgis_core.getCenter(featureList[j].geometry);
						if(Math.abs(targetCenterPoint.x - currentCenterPoint.x) <= buf && 
								Math.abs(targetCenterPoint.y - currentCenterPoint.y) <= buf){
							return false;
						}
					}
					return true;
				},

				/**
				 * 设置分页索引并且重新计算数据
				 */
				setPageIndex : function(searchName, pageIndex, noPageResults){
					$gisObject.searchParameter[searchName].searchPageIndex = pageIndex;
					$gisObject.searchParameter[searchName].searchPageList = [];
					if($gisObject.searchParameter[searchName].searchRowCount<=0){
						return;
					}

					var pageSize = $gisObject.searchParameter[searchName].searchPageSize;
					var endIndex = pageIndex * pageSize;
					var beginIndex = endIndex - pageSize;

					if(beginIndex > $gisObject.searchParameter[searchName].searchRowCount -1){
						return;
					}

					if(endIndex>$gisObject.searchParameter[searchName].searchRowCount){
						endIndex=$gisObject.searchParameter[searchName].searchRowCount;
					}

					for(var i=beginIndex;i<endIndex;i++){
						var obj = $gisObject.searchParameter[searchName].searchResultList[i];
						$gisObject.searchParameter[searchName].searchPageList.push(obj);
						if(i==beginIndex){
							
							var currentSelectedFeature = $gisObject.currentSelectedFeature;
							if(!currentSelectedFeature){
								$gisObject.currentSelectedFeature  = obj;
								currentSelectedFeature = obj;
							}
							$gisObject.currentSelectedFeature  = obj;
							if(obj!=currentSelectedFeature){
								$itfreer_arcgis_search.unSelectFeature(currentSelectedFeature.attributes.OBJECTID,'station');
							}
							$itfreer_arcgis_search.selectFeature($gisObject.currentSelectedFeature.attributes.OBJECTID,'station');
						}
					}
					if(noPageResults && noPageResults==true){
						return;
					}else{
						//commented by lrs
						//$itfreer_arcgis_search.showPageResults(searchName);
					}
				},
				
				/**
				 * 上一页
				 */
				preGisPage : function(searchName){
					var pageIndex = $gisObject.searchParameter[searchName].searchPageIndex;
					pageIndex--;
					if(pageIndex<=0){
						pageIndex =1 ;
					}
					$itfreer_arcgis_search.setPageIndex(searchName, pageIndex);
				},
				
				/**
				 * 下一页
				 */
				nextGisPage : function(searchName){
					var pageIndex = $gisObject.searchParameter[searchName].searchPageIndex;
					var pageCount = $gisObject.searchParameter[searchName].searchPageCount;
					pageIndex++;
					if(pageIndex>pageCount){
						pageIndex = pageCount ;
					}
					$itfreer_arcgis_search.setPageIndex(searchName, pageIndex);
				},
				
				/**
				 * 首页
				 */
				firstGisPage : function(searchName){
					$itfreer_arcgis_search.setPageIndex(searchName, 1);
				},
				
				/**
				 * 尾页
				 */
				lastGisPage : function(searchName){
					var pageCount = $gisObject.searchParameter[searchName].searchPageCount;
					$itfreer_arcgis_search.setPageIndex(searchName, pageCount);
				},

			    /**
				 * 高亮选中小气泡
				 */
			    selectPop : function(objectid, searchName){
			    	var graphic = $itfreer_arcgis_core.getGraphicByPop(objectid, searchName);
				   	if(!graphic){
				   		return;
				   	}
				   	$itfreer_arcgis_search.selectPopByGraphic(graphic,searchName);
			    },

			    /**
				 * 高亮选中小气泡
				 */
			    selectPopByGraphic : function(graphic,searchName){
				   	if(!graphic){
				   		return;
				   	}

				   	// 如果是自定义小气泡
			    	var i = graphic.attributes.$popindxe;
			    	// 设置小气泡
					var iconName = "arrow";
					var iconURL = getJsBasePath()+"/wdp/images/highlight.png";
					var pMark = new esri.symbol.PictureMarkerSymbol(iconURL, 20, 20);
					graphic.setSymbol(pMark);
			    },

			    /**
				 * 取消高亮选中小气泡
				 */
			    unSelectPop : function(objectid, searchName){
			    	var graphic = $itfreer_arcgis_core.getGraphicByPop(objectid, searchName);
				   	if(!graphic){
				   		return;
				   	}
				   	$itfreer_arcgis_search.unSelectPopByGraphic(graphic,searchName);
			    },

			    /**
				 * 取消高亮选中小气泡
				 */
			    unSelectPopByGraphic : function(graphic,searchName){
				   	if(!graphic){
				   		return;
				   	}
				   	
				   	// 如果是自定义小气泡
			    	var i = graphic.attributes.$popindxe;
			    	var iconName = "arrow";
//					if(i<=9){
//						iconName = i.toString();
//					}
					var iconURL = getJsBasePath()+"/arcgis/images/features/" + iconName + ".png";
					var pMark = new esri.symbol.PictureMarkerSymbol(iconURL, 25, 35);
					graphic.setSymbol(pMark);
			    },

			    /**
				 * 高亮选中查询要素
				 */
			    selectFeature : function(objectid, searchName){
			    	try{
			    		var graphic = $itfreer_arcgis_core.getGraphicByFeature (objectid, searchName);
			    		if(!graphic){
			    			return;
			    		}
			    		$itfreer_arcgis_search.selectFeatureByGraphic(graphic,searchName);
			    	}catch(e){
			    		console.log(e);
			    	}
			    },

			    /**
				 * 高亮选中查询要素
				 */
			    selectFeatureByGraphic : function(graphic,searchName){
				   	if(!graphic){
				   		return;
				   	}
				   	var getSymbolFunction = $gisObject.searchParameter[searchName].getSelectedSymbol;
				   	if(getSymbolFunction != null){
			       		symbol = getSymbolFunction(graphic);
			       	}
			       	if(symbol == null ){
			       		symbol = $itfreer_arcgis_search.getSelectFillSyml();
				       	if(graphic.geometry.type == "point"){
				       		symbol = $itfreer_arcgis_search.getSelectPointSyml();
				       	}
			       	}
			       	if(graphic.getShape()!=null){
			       		graphic.getShape().moveToFront();
			       	}
					graphic.setSymbol(symbol);
			    },

			    /**
				 * 取消高亮选中查询要素
				 */
			    unSelectFeature : function(objectid, searchName){
			    	var graphic = $itfreer_arcgis_core.getGraphicByFeature (objectid, searchName);
				   	if(!graphic){
				   		return;
				   	}
					$itfreer_arcgis_search.unSelectFeatureByGraphic(graphic, searchName);
			    },

			    /**
				 * 取消高亮选中查询要素
				 */
			    unSelectFeatureByGraphic : function(graphic,searchName){
				   	if(!graphic){
				   		return;
				   	}
				   	
				   	if($gisObject.currentSelectedFeature.attributes.OBJECTID==graphic.attributes.OBJECTID){
				   		return;
				   	} 
				   	
				   	var symbol = graphic.defaultSymbol;
				   	if(symbol == null){
				   		symbol = $itfreer_arcgis_search.getDefaultFillSyml();
				       	if(graphic.geometry.type == "point"){
				       		symbol = $itfreer_arcgis_search.getDefaultPointSyml();
				       	}
				   	}
					graphic.setSymbol(symbol);
					
					if(graphic.getShape()!=null){
			       		graphic.getShape().moveToBack();
			       	}
			    },

			    /**
				 * 显示详细信息窗口
				 */
			    showInfoWindowByPop : function (objectid, searchName){
			    	var graphic = $itfreer_arcgis_core.getGraphicByPop(objectid, searchName);
				   	if(!graphic){
				   		return false;
				   	}
			    	$itfreer_arcgis_search.showInfoWindowByGraphic(graphic);
			    	return true;
			    },

			    /**
				 * 显示详细信息窗口
				 */
			    showInfoWindowByFeature : function (objectid, searchName){
			    	var graphic = $itfreer_arcgis_core.getGraphicByFeature(objectid, searchName);
				   	if(!graphic){
				   		return false;
				   	}
				   	$itfreer_arcgis_search.showInfoWindowByGraphic(graphic);
				   	return true;
			    },

			    /**
				 * 显示详细信息窗口
				 */
			    showInfoWindow : function(objectid, searchName){
			    	if($itfreer_arcgis_search.showInfoWindowByPop(objectid, searchName)){
			    		return true;
			    	}else if($itfreer_arcgis_search.showInfoWindowByFeature(objectid, searchName)){
			    		return true;
			    	}
			    	return false;
			    },

			    /**
				 * 显示详细信息窗口
				 */
			    showInfoWindowByGraphic : function (graphic){
				   	if(!graphic){
				   		return;
				   	}

			       	var _extent = $itfreer_arcgis_core.getCenter(graphic.geometry);
			       	$gisObject.map.infoWindow.show(_extent);
			    },

			    /**
				 * 绽放到
				 */
			    setGraphicExtent : function(objectid, searchName){
			    	var graphic = $itfreer_arcgis_core.getGraphicByFeature(objectid, searchName);
				   	if(!graphic){
				   		return;
				   	}

					//设置地图视图范围
				   	if(graphic.geometry.type == "point"){
				   		$gisObject.map.centerAt(graphic.geometry);
				   		return;
			       	}
			       	var rExtent = $itfreer_arcgis_core.getMaxExtent([graphic]);
			    	$gisObject.map.setExtent(rExtent);
			    },
			    
			    /**
				 * 绽放到
				 */
			    setGraphicExtentLRQ : function(graphic){
				   	if(!graphic){
				   		return;
				   	}

					//设置地图视图范围
				   	if(graphic.geometry.type == "point"){
				   		$gisObject.map.centerAt(graphic.geometry);
				   		return;
			       	}
			       	var rExtent = $itfreer_arcgis_core.getMaxExtent([graphic]);
			    	$gisObject.map.setExtent(rExtent);
			    },

			    /**
				 * 清除查询结果，并返回查询页面
				 */
			    clearSearchResult : function(searchName){
			    	$gisObject.searchParameter[searchName].searchPanel = true;
			    	$itfreer_arcgis_draw.deDrawAndClearGraphics();

			    	// 清除查询数据
			       	if($gisObject.searchParameter[searchName].resultLayerIds
			       		&& $gisObject.searchParameter[searchName].resultLayerIds.length>0){
			       		for(var i=0;i<$gisObject.searchParameter[searchName].resultLayerIds.length;i++){
			       			var tempLN = $gisObject.searchParameter[searchName].resultLayerIds[i];
			       			$gisObject.searchParameter[tempLN] = {};
			       		}
			       	}
			       	$gisObject.searchParameter[searchName].resultLayerIds = [];
			       	$gisObject.searchParameter[searchName].searchResultList = [];
					$gisObject.searchParameter[searchName].searchPageList = [];
			    },

			     /**
				 * 显示指定查询面板
				 */
			    showSearchTab : function(searchName, id){
			    	$itfreer_form_core.setTab(searchName, 'tab' + id);
			    	$itfreer_arcgis_search.showPageResults(searchName + '_' + id);
			    },

			    /**
				 * 是否可显示tab选项卡
				 */
			    canShowTab : function(searchName, id){
			    	return $itfreer_arcgis_search.hasLayer(searchName, id) && $formObject.tabs[searchName].tabShow['tab'+id];
			    },

			    showPopAndFeature : function(objectid, searchName){
			    	$itfreer_arcgis_search.selectPop(objectid, searchName);
			    	$itfreer_arcgis_search.selectFeature(objectid, searchName);
			    },

			    hidePopAndFeature : function(objectid, searchName){
			    	$itfreer_arcgis_search.unSelectPop(objectid, searchName);
			    	$itfreer_arcgis_search.unSelectFeature(objectid, searchName);
			    }
			};
			for(f in $itfreer_arcgis_search){
				$rootScope[f] = $itfreer_arcgis_search[f];
			}
			return $itfreer_arcgis_search;
		}
	);

	/* 
	 * 加载服务器
	 */
	itfreerArcgisSearchModule.run(function($rootScope, $itfreer_arcgis_search) {
	  	
	});
}(window, angular));